/*
 * Created on Oct 12, 2005
 *
 */
	package littlecyberwar.ui;

	import java.util.*;
	import java.awt.*;
	import java.awt.event.*;
	import javax.swing.*;
	import java.io.*;


	import littlecyberwar.model.*;
	import littlecyberwar.ui.*;
	import littlecyberwar.util.*;
	import littlecyberwar.tool.MouseHandler;
	/**
	 * @author Milton  Soong
	 *
	 * To change the template for this generated type comment go to
	 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
	 */
	public class ChangeLayerAction extends LCWAction { 
		private static ChangeLayerAction instance = null;
		
		private ChangeLayerDialog changeLayerDiag = null;
		private InternalCmdFacade mod;
		
	  PlayingBoardPanel pbp;
	   public ChangeLayerAction(String text, 
						 ImageIcon icon,
						 String desc, 
						 KeyStroke k, 
						 MainFrame fr, 
						 PlayingBoardPanel pbpIn, 
						 String mouseHandlerClassName) {
			   super(text, icon, desc, k, fr);
			   pbp = pbpIn;
			   mod = fr.getIcmd();
			   instance = this;
			
			   // The class for the action is loaded here
			   MouseHandler	handler=null;	
			   if ( mouseHandlerClassName != null ) {
				  ClassLoader loader = this.getClass().getClassLoader();
				  try {
					Class cl = loader.loadClass("littlecyberwar.tool." + mouseHandlerClassName);
				handler = (MouseHandler)cl.newInstance();
			
			  } catch ( Exception ex ) {
				ex.printStackTrace();
			  }
			  if ( handler != null ) {
			   handler.setBoardPanel(pbp);
			   putValue(ModeAction.LCW_MOUSEHANDLER, handler);	
			   MainFrame mf = (MainFrame)fr;
			   ProfileCardPanel pp = mf.getProfilePanel();
			   CardLayout ppc = mf.getProfilePanelCard();
			   handler.setProfilePanel(pp);
			   handler.setProfilePanelCard(ppc);
			  }
			}		
	   }
		
	  public void actionPerformed(ActionEvent e) {
	  	if ( changeLayerDiag == null ) {
	  		// the remove dialog has not been set yet
			JOptionPane.showMessageDialog(frame,
				"No Layers have been defined yet. Please open a scenario file first.");
	  	} else {
			Dimension dlgSize = changeLayerDiag.getPreferredSize();
			Dimension frmSize = frame.getSize();
			Point loc = frame.getLocation();
			changeLayerDiag.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);	
			changeLayerDiag.show();
	  	}
	  	return;
	  }
	  
	  public void setChangeLayerDialog(ChangeLayerDialog diag) {
		  changeLayerDiag = diag;
	  }
	  
	  public static ChangeLayerAction getInstance() {
	  	return ( instance );
	  }

}
